//UMASS Lowell
//SW Engineering
//Spring 2010
//Project: BUFDB - Setup component
//Version: 3
//Author: Chuck DeLoid
//Date: 5/4/10
//Purpose: A C++ program that uses the PostgreSQL libpq to connect to a postgreSQL //database server and create a database

#include <boost/algorithm/string/join.hpp>
#include <boost/program_options.hpp>

using namespace boost;
namespace po = boost::program_options;

#include <iostream>  
#include <string>

#include <libpq-fe.h>
#include <libpq/libpq-fs.h>

#include "bufferSetup.h"
#include "database.pb.h"
#include "connect.h"

main(int argc, char* argv[]) {
    bufferSetup *bs = new bufferSetup(argc, argv);    

    bs->createTableName();

    string results("");

    vector<string>::iterator p;
    for (p=bs->commands_.begin(); p!=bs->commands_.end(); p++) {
        cerr << *p << endl;

        PGresult * result = PQexec(bs->con, (*p).c_str());

        if (PQresultStatus(result) != PGRES_COMMAND_OK) {
            string duh(PQerrorMessage(bs->con));
            string rstr("Command failed: " + duh);
            results += rstr;
            PQclear(result);
        }
    }

    cerr << results;

    return 0;
}
